If you are a sportsman, you will love our interactive map!
In this notebook there will be content designed specifically for users, others for programmers.
This distinction is made explicit by the use of the following icons:
We import the necessary libraries for the notebook to correctly work.
import gpxpy
import pandas as pd
from datetime import datetime,timezone,timedelta
import geopandas as gpd
from geopy.geocoders import Nominatim
import movingpandas as mpd
import contextily as ctx
import folium
import leafmap
import pyrosm
import os
import sys
# Ignore warnings
import warnings
warnings.filterwarnings("ignore")
# Import custom modules
sys.path.insert(0, os.path.abspath('../')) # need to pass absolute path in nb
from functions.dataviz_folium import *
from functions.dataviz_geopandas import extract_data_from_OSM
print("> Setup Completed")
> Setup Completed
First we briefly explore the routes we have obtained thanks to mapstogpx.com/strava.
# import gpx file
udine_run_cormor = read_gpx("../data/strava/udine_run_parco_cormor.gpx")
# and show info about tracks, segments and points
print("Parco del Cormor")
print_gpx_info(udine_run_cormor)
# we do the same for the other tracks
udine_run_cormor_sud = read_gpx("../data/strava/udine_run_parco_cormor_sud.gpx")
print("\nParco del Cormor Sud")
print_gpx_info(udine_run_cormor_sud)
laipacco_run_dirt_road = read_gpx("../data/strava/laipacco_run_dirt_road.gpx")
print("\nLaipacco - Dirt Road")
print_gpx_info(laipacco_run_dirt_road)
reana_del_rojale_run = read_gpx("../data/strava/reana_del_rojale_run.gpx")
print("\nReana del Rojale")
print_gpx_info(reana_del_rojale_run)
udine_run_monte_grappa = read_gpx("../data/strava/udine_run_monte_grappa.gpx")
print("\nVia Monte Grappa")
print_gpx_info(udine_run_monte_grappa)
Parco del Cormor Creator: https://www.mapstogpx.com/strava > Track 0 > Segment 0 has 550 points Parco del Cormor Sud Creator: https://www.mapstogpx.com/strava > Track 0 > Segment 0 has 754 points Laipacco - Dirt Road Creator: https://www.mapstogpx.com/strava > Track 0 > Segment 0 has 603 points Reana del Rojale Creator: https://www.mapstogpx.com/strava > Track 0 > Segment 0 has 1026 points Via Monte Grappa Creator: https://www.mapstogpx.com/strava > Track 0 > Segment 0 has 514 points
percoto_bike = read_gpx("../data/strava/percoto_bike.gpx")
print("Percoto")
print_gpx_info(percoto_bike)
udine_center_bike = read_gpx("../data/strava/udine_center_bike.gpx")
print("\nPagnacco")
print_gpx_info(udine_center_bike)
basiliano_bike = read_gpx("../data/strava/basiliano_bike.gpx")
print("\nBasiliano")
print_gpx_info(basiliano_bike)
Percoto Creator: https://www.mapstogpx.com/strava > Track 0 > Segment 0 has 8571 points Pagnacco Creator: https://www.mapstogpx.com/strava > Track 0 > Segment 0 has 2161 points Basiliano Creator: https://www.mapstogpx.com/strava > Track 0 > Segment 0 has 3711 points
In addition to the routes, it would be interesting to show the fitness centres on the map.
We use OSM data to achieve this.
# import the .pbf file of the city, obtained through Wikimedia Italy
udine_osm = pyrosm.OSM("../data/udine.osm.pbf")
# obtain the fitness points in Udine
fitness_points = extract_data_from_OSM(udine_osm, "leisure", secondary_filter=["fitness_centre","sports_centre"])
# find representative points
fitness_points["geometry"] = fitness_points.representative_point().geometry
# show data
fitness_points[["id","lat","lon","name","geometry"]].head()
| id | lat | lon | name | geometry | |
|---|---|---|---|---|---|
| 0 | 3170278108 | 46.075985 | 13.245296 | WellGym | POINT (13.24530 46.07598) |
| 1 | 3670530418 | 46.084778 | 13.224745 | Ancona | POINT (13.22474 46.08478) |
| 2 | 3748924274 | 46.071285 | 13.235895 | Ladies | POINT (13.23590 46.07129) |
| 3 | 3748943032 | 46.060730 | 13.248013 | Spazio movimento | POINT (13.24801 46.06073) |
| 4 | 3748980991 | 46.059467 | 13.226983 | Let's move | POINT (13.22698 46.05947) |
We add all the information to an interactive map that the user can use to find the running and cycling routes he or she considers most suitable.
The map, having the city of Udine as its centre, can be explored through 3 layers:
It is possible to change layers via the control centre in the top right-hand corner.
There are two types of routes: running and cycling. Both are based on real data obtained from Strava users.
It is possible to show only the desired route category via the control centre.
The routes are distinguishable by the icons representing them, located at the beginning of the route.
By passing the cursor over the markers, the name of the route is shown.
Clicking on the icons will instead display information such as:
The sports centres in Udine are also available on the map. Due to their number they are displayed in clusters. They can be viewed from the control centre at the top right.
# Setup
udine_lat = 46.0609604
udine_lon = 13.1980551
list_of_layers = ['Stamen Terrain','cartodbpositron']
list_of_routes = [
[create_geodf_from_segment(udine_run_cormor, 0, 0), "Run in Parco del Cormor", "run"],
[create_geodf_from_segment(udine_run_cormor_sud, 0, 0), "Run in Parco del Cormor Sud", "run"],
[create_geodf_from_segment(laipacco_run_dirt_road, 0, 0), "Run in Laipacco, Dirt Road", "run"],
[create_geodf_from_segment(reana_del_rojale_run, 0, 0), "Run in Reana del Rojale", "run"],
[create_geodf_from_segment(udine_run_monte_grappa, 0, 0), "Run in Via Monte Grappa", "run"],
[create_geodf_from_segment(percoto_bike, 0, 0), "Percoto Bike Intensive Route", "bike"],
[create_geodf_from_segment(udine_center_bike, 0, 0), "Udine Center Bike Route", "bike"],
[create_geodf_from_segment(basiliano_bike, 0, 0), "Basiliano Bike Route", "bike"]
]
list_of_points = [
[fitness_points, "fitness"]
]
# Create interactive map
interactive_map = create_folium_map(
udine_lat, udine_lon,
list_of_layers,
list_of_routes,
list_of_points
)
# Show it
interactive_map
> Creating Base Map > Adding multiple layers > Adding routes - Added run route: Run in Parco del Cormor - Added run route: Run in Parco del Cormor Sud - Added run route: Run in Laipacco, Dirt Road - Added run route: Run in Reana del Rojale - Added run route: Run in Via Monte Grappa - Added bike route: Percoto Bike Intensive Route - Added bike route: Udine Center Bike Route - Added bike route: Basiliano Bike Route > Adding points > Interactive Map Created